#include "EvalBleedThroughIntensity2Back.hpp"

#include "ThresholderOtsuBleedThroughAware.hpp"



/** @todo cleanup */
float EvalBleedThroughIntensity2Back::evaluate(const girl::tools::Image &image)
{

    ThresholderOtsuBleedThroughAware thresholder;
    int s_verso = thresholder.getVersoTreshold(getVerso());
    int s_recto = thresholder.getRectoThreshold(image,getVerso(),s_verso);

    std::cout << "seuil verso" << s_verso << std::endl;
    std::cout << "seuil recto" << s_recto << std::endl;


    float s=0;
    float nb =0;

    float sum_back = 0;
    float nb_back = 0;
    for(int i = 0; i < image.width(); i++)
    {
        for (int j= 0; j  < image.height(); j++)
        {
            if(getVerso().getPixel(i,j).a() < s_verso)
            {
                s+=image.getPixel(i,j).a();
                nb++;
            }
            if(getVerso().getPixel(i,j).a() > s_verso && image.getPixel(i,j).a() > s_recto)
            {
                sum_back+=image.getPixel(i,j).a();
                nb_back++;
            }
        }
    }
    float moyenne_back = sum_back / nb_back;
    float moyenne_bleed = s/nb;
    std::cout << "moyenne back" << moyenne_back<< std::endl;
    std::cout << "moyenne Bleed" << moyenne_bleed << std::endl;
    return (moyenne_back - moyenne_bleed ) / 255 ;
}
